package cn.exrick.service.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.exrick.mapper.TbCommentMapper;
import cn.exrick.pojo.TbComment;
import cn.exrick.service.CommentService;
import cn.exrick.utils.mybatis.Criteria;

@Service
public class CommentServiceImpl extends BaseServiceImpl<TbComment, TbCommentMapper> implements CommentService {
    private final static Logger log = LoggerFactory.getLogger(CommentServiceImpl.class);

    @Override
    public Logger getLogger() {
        return log;
    }

    public Criteria createCriteria(Map<String, Object> params) {
        Criteria criteria = createCriteria();
        if (params.get("content") != null) {
            criteria.andFieldLike("content", (String) params.get("content"));
        }
        if (params.get("score") != null) {
            criteria.andFieldEqualTo("score", String.valueOf((Double) params.get("score")));
        }
        if (params.get("itemId") != null) {
            criteria.andFieldEqualTo("item_id", String.valueOf((Long) params.get("itemId")));
        }
        if (params.get("memberId") != null) {
            criteria.andFieldEqualTo("member_id", String.valueOf((Long) params.get("memberId")));
        }
        return criteria;
    }

    @Autowired
    TbCommentMapper tbCommentMapper;

    @Override
    public TbCommentMapper getMapper() {
        return tbCommentMapper;
    }
}
